package com.itheima.travel.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.travel.domain.Route;
import com.itheima.travel.service.RouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/route")
public class RouteController {

    @Autowired
    private RouteService routeService;

    @RequestMapping("/findByPageByCid")
    public PageInfo<Route> findByPageByCid(int cid,
                                           @RequestParam(defaultValue = "1") int pageNum,
                                           @RequestParam(defaultValue = "") String rname) {
        return routeService.findByPageByCid(cid, pageNum, rname);
    }

    @RequestMapping("/findRouteByRid")
    public Route findRouteByRid(Integer rid) {
        return routeService.findRouteByRid(rid);
    }

    @RequestMapping("/findByPage")
    public PageInfo<Route> findByPage(@RequestParam(defaultValue = "1") int pageNum,
                                      String pMin,String pMax,String rname) {
        return routeService.findByPage(pageNum,pMin,pMax,rname);
    }
}
